package com.caiyi.financial.nirvana.sms.shiro;

import com.caiyi.financial.nirvana.sms.enums.ReturnCodeEnum;
import com.caiyi.financial.nirvana.sms.util.Constant;
import com.youyu.common.api.Result;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * Created by Mario on 2018/1/4 0004.
 * Shiro验证失败信息控制器
 */
@RestController
@RequestMapping("/sms/shiro")
public class ShiroHandler {

    /**
     * 登录认证异常
     *
     * @param response HttpServletResponse
     * @return 用户未登录
     */
    @RequestMapping("/unauthenticated")
    public Result unauthenticatedHandler(HttpServletResponse response) {
        response.setCharacterEncoding(Constant.CHARSET_UTF8);
        Result Result = new Result();
        Result.setCode(ReturnCodeEnum.NOT_LOGIN_ERROR.code);
        Result.setDesc(ReturnCodeEnum.NOT_LOGIN_ERROR.desc);
        return Result;
    }

    /**
     * 权限异常
     *
     * @param response HttpServletResponse
     * @return 没有权限
     */
    @RequestMapping("/unauthorized")
    public Result unauthorizedHandler(HttpServletResponse response) {
        response.setCharacterEncoding(Constant.CHARSET_UTF8);
        Result Result = new Result();
        Result.setCode(ReturnCodeEnum.FAILED.code);
        Result.setDesc("没有权限");
        return Result;
    }
}
